import { commit_remark } from "@/services/sickbeds";
import { ActionType, ProForm, ProFormTextArea } from "@ant-design/pro-components";
import { Divider, Modal, message } from "antd"

interface Iprops {
    isShowAddRecord: (show: boolean) => void;
    isAddRecordModalOpen: boolean;
    id: number | undefined
    recordActionRef?: React.MutableRefObject<ActionType | undefined>;
}
const AddRecord = (props: Iprops) => {
    const { isShowAddRecord, isAddRecordModalOpen, id,recordActionRef} = props;

    // 添加呼叫记录备注信息
    const add_commit_remark = async (value: any) => {
        let request_body = {
            ...value,
            id,
        }
        let res:any=await commit_remark(request_body);
        if(res.code==200){
            message.success('添加记录成功！');
            recordActionRef?.current?.reload();
            isShowAddRecord(false);
            window.opener.postMessage('refreshCallList', '*');
            setTimeout(()=>{
                window.close();
            },500)  
        }else{
            message.error(res.msg)
        }
    }
    return (
        <Modal
            title="添加记录"
            open={isAddRecordModalOpen}
            onCancel={() => {
                isShowAddRecord(false)
                setTimeout(()=>{
                    window.close();
                },500)
            }}
            width={500}
            destroyOnClose={true}
            footer={null}
            centered
        >
            <Divider />
            <ProForm
                layout="horizontal"
                labelCol={{ span: 5 }}
                wrapperCol={{ span: 20 }}
                onReset={() => {
                    isShowAddRecord(false);
                    setTimeout(()=>{
                        window.close();
                    },500)
                }}
                onFinish={(value) => add_commit_remark(value)}
                submitter={{
                    // 配置按钮文本
                    searchConfig: {
                        resetText: '取消',
                        submitText: '提交',
                    },
                    resetButtonProps: {
                        style: {
                            display: 'block',
                            position: 'absolute',
                            left: 'calc(50% - 107px)',
                        },
                    },
                    submitButtonProps: {
                        style: {
                            display: 'block',
                            position: 'absolute',
                            right: 'calc(50% - 107px)',
                        },
                    },
                }}
            >
                <ProFormTextArea
                    name="remark"
                    label="记录内容"
                    placeholder="请输入记录内容"
                />
                <br />
            </ProForm>
            <br />
        </Modal>
    )

}
export default AddRecord;